﻿using FluentValidation.Validators;

namespace CleanArchitecture.Web.Validators
{
    /// <summary>
    /// Username validator
    /// </summary>
    public class AdminUserPasswordPropertyValidator : PropertyValidator
    {
        private int _minLen;
        /// <summary>
        /// Ctor
        /// </summary>
        public AdminUserPasswordPropertyValidator(int passwordminLen)
            : base(string.Format(ValidatorRuleString.PasswordNumLimit, passwordminLen))
        {
            this._minLen = passwordminLen;
        }

        /// <summary>
        /// Is valid?
        /// </summary>
        /// <param name="context">Validation context</param>
        /// <returns>Result</returns>
        protected override bool IsValid(PropertyValidatorContext context)
        {
            return IsValid(context.PropertyValue as string, this._minLen);
        }

        /// <summary>
        /// Is valid?
        /// </summary>
        /// <param name="username">Username</param>
        /// <param name="customerSettings">Customer settings</param>
        /// <returns>Result</returns>
        public static bool IsValid(string password, int passwordminLen)
        {
            return password.Length >= passwordminLen;
        }
    }
}
